package jnBase.script
{
	import laya.components.Script;
	import laya.events.Event;
	import laya.ui.Label;
	import laya.utils.Browser;
	import laya.utils.Ease;
	import laya.utils.Tween;
	
	public class MouseOverShowMsg extends Script
	{
		/** @prop {name:value,tips:"显示标签",type:String}*/
		public var value:String;
		/** @prop {name:direction,tips:"显示方向",type:String}*/
		public var direction:String="left";
		private var msg:Label;
		public function MouseOverShowMsg()
		{
			super();
			Laya.timer.frameOnce(5,this,ready);
		}
		private function ready():void
		{
			msg=new Label();
			msg.text=value;
			msg.fontSize=22;
			msg.color="#ffffff";
			owner.addChild(msg);
			owner.setChildIndex(msg,0);
			msg.y=30;
			if(Browser.onPC || Browser.onMac){
				if(direction=='left'){
					msg.x=30;
				}
				else if(direction=="right"){
					msg.x=-msg.width/2;
				}
				msg.alpha=0;
				owner.on(Event.MOUSE_OVER,this,onOver);
				owner.on(Event.MOUSE_OUT,this,onOut);
			}
			else{
				msg.alpha=1;
				if(direction=='left'){
					msg.x=70;
				}
				else if(direction=="right"){
					msg.x=-msg.width;
				}
			}
		}
		
		private function onOut():void
		{
			// TODO Auto Generated method stub
			if(direction=='left'){
				Tween.to(msg,{alpha:0,x:30},300,Ease.circInOut);
			}
			else if(direction=="right"){
				Tween.to(msg,{alpha:0,x:-msg.width/2},300,Ease.circInOut);
			}
		}
		
		private function onOver():void
		{
			// TODO Auto Generated method stub
			trace("direction");
			if(direction=='left'){
				Tween.to(msg,{alpha:1,x:100},300,Ease.circInOut);
			}
			else if(direction=="right"){
				Tween.to(msg,{alpha:1,x:-msg.width-10},300,Ease.circInOut);
			}
			
		}
	}
}